home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / ATARI.C < prev    next >
C/C++ Source or Header  |  1990-10-06  |  63KB  |  2,377 lines

  1. /*
  2.  * Atari ST-specific functions
  3.  * written by Rob Janssen, PE1CHL
  4.  * 3 configurations are possible:
  5.  *    .TOS
  6.  *    .ACC    define GEM and GEMACC
  7.  *    .PRG    define GEM and GEMPRG
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <ctype.h>
  12. #ifdef MWC
  13. # include <osbind.h>            /* os interface defines */
  14. # define Kbshift    Getshift    /* MW goofed... */
  15. #endif
  16. #ifdef __TURBOC__
  17. # define cdecl
  18. # include <tos.h>            /* os interface defines */
  19. #endif
  20. #include <linea.h>            /* line-A interface defines */
  21. #include <time.h>
  22.  
  23. #ifdef __TURBOC__            /* line-A access for Turbo C */
  24. # define VPLANES    Linea->v_planes
  25. # define V_CEL_HT    Vdiesc->v_cel_ht
  26. # define V_CEL_MX    Vdiesc->v_cel_mx
  27. # define V_CEL_MY    Vdiesc->v_cel_my
  28. # define V_CUR_AD    ((char *) (Vdiesc->v_cur_ad))
  29. # define V_CUR_OFF    Vdiesc->v_cur_off
  30. # define V_CUR_CX    Vdiesc->v_cur_xy[0]
  31. # define V_CUR_CY    Vdiesc->v_cur_xy[1]
  32. # define V_FNT_AD    ((char *) (Vdiesc->v_fnt_ad))
  33. #endif
  34.  
  35. #include "global.h"
  36. #include "config.h"
  37. #include "mbuf.h"
  38. #include "internet.h"
  39. #include "iface.h"
  40. #include "atari.h"
  41. #include "timer.h"
  42. #include "environ.h"
  43.  
  44. extern unsigned nasy;
  45.  
  46. /* Interface list header */
  47. struct interface *ifaces;
  48.  
  49. #ifdef OUTBUF
  50. static char *ttbuf;
  51. #endif
  52.  
  53. int  auxcon = 0;            /* auxcon control word */
  54. #define AUXCOUT        0x01        /* send out to AUX */
  55. #define AUXCNOT        0x02        /* don't send out to screen */
  56. #define AUXCIN        0x10        /* read input from AUX */
  57. int  auxitrn[256];            /* aux input translate table */
  58. char auxotrn[256];            /* aux output translate table */
  59.  
  60. int  screenmode = 0;            /* screen output control word */
  61. #define SCRTOS        0        /* output via TOS */
  62. #define SCRBIOS        1        /* output via BIOS */
  63. #define SCRDIR        2        /* direct output to screen */
  64.  
  65. extern void trap_x();            /* handler for trap #5/#11 */
  66. void (*trap_x_save)();            /* saved trap #5/#11 handler */
  67.  
  68. extern char startup[];            /* startup file name */
  69.  
  70. extern FILE *logfp;            /* log file pointer */
  71. extern char logname[];            /* log file name */
  72.  
  73. extern FILE *trfp;            /* trace file pointer */
  74. extern char trname[];            /* trace file name */
  75.  
  76. #ifdef GEM
  77.  
  78. #define     WORD        int        /* signed word (16 bits) */
  79. #define     TRUE        (1)        /* TRUE     value */
  80. #define     FALSE        (0)        /* FALSE value */
  81.  
  82. #include <gemdefs.h>            /* MW GEM definitions */
  83. #include <obdefs.h>
  84.  
  85. #define     MAXWIN        8        /* maximal window handle from GEM */
  86. #define     USEWIN        2        /* windows used by this application */
  87.  
  88. #define     DESK        0        /* window number for desktop */
  89. #define     ALIGN(x,n)    (x) = (n * (((x) + (n / 2)) / n))/* align x to n incr. */
  90.  
  91. #define     WI_KIND    (HSLIDE|RTARROW|LFARROW|VSLIDE|DNARROW|UPARROW|SIZER|MOVER|FULLER|CLOSER|NAME)
  92.  
  93. #define     MIN_WIDTH    (16 * gr_hwbox) /* minimal window width */
  94. #define     MIN_HEIGHT    (5 * gr_hhbox)    /* minimal window height */
  95.  
  96. #define     MAXLINE    100        /* history lines saved */
  97. #define     MAXCHAR    80        /* max characters on each line */
  98.  
  99. /*** datatypes ***/
  100.  
  101. typedef struct linehist            /* define 'line history' type */
  102. {
  103.    struct linehist *next;        /* forward link */
  104.    struct linehist *prev;        /* backward link */
  105.    int    len;                /* this one's length */
  106.    char line[1];            /* the actual line to be stored */
  107. } LINEHIST;
  108.  
  109. typedef struct                /* define 'sliding window' type */
  110. {
  111.    long total;                /* total size in this dimension */
  112.    long pos;                /* pos of portion currently seen */
  113.    int    seen;                /* size of portion currently seen */
  114. } SLWIN;
  115.  
  116. typedef struct window            /* info about windows */
  117. {
  118.    WORD     win;                /* corresponding window handle */
  119.    WORD     kind;                /* this window's wi_kind */
  120.    WORD     pobj;                /* object selected there */
  121.    GRECT work;                /* work area pos/size */
  122.    GRECT full;                /* full size of window */
  123.    GRECT org;                /* originating pos/size for shrink */
  124.    SLWIN hori;                /* horizontal slider info */
  125.    SLWIN vert;                /* vertical slider info */
  126.    LINEHIST *head;            /* head of line history */
  127.    LINEHIST *tail;            /* tail of line history */
  128.    int     curpos;            /* position on current line */
  129.    char     curline[MAXCHAR + 1];        /* current line */
  130.    char     cursor;            /* cursor state */
  131.    char     open;                /* window opened? */
  132.    char     title[MAX_LEN];        /* window title (if any) */
  133.    char     info[MAX_LEN];            /* window info (if any) */
  134. } WINDOW;
  135.  
  136. /*** GLOBAL VARIABLES ***/
  137.  
  138. /* GEM handles, information and the like */
  139.  
  140. extern WORD gl_apid;            /* application id (external to MWC) */
  141. WORD gl_mnid;                /* menu id for this accessory */
  142. WORD gr_handle;                /* physical workstation handle */
  143. static WORD handle;            /* virtual workstation handle */
  144.  
  145. WORD gr_hhchar,gr_hwchar,gr_hhbox,gr_hwbox;/* system font sizes */
  146.  
  147. /* window management datastructures */
  148.  
  149. static WINDOW window[USEWIN];        /* window info, DESK + user windows */
  150. static WORD win[MAXWIN];        /* handle to application conv. */
  151. static WORD topwin = -1;        /* top (=current) window handle */
  152.  
  153. static WORD await = MU_MESAG|MU_TIMER;    /* select initially active events */
  154. static GRECT m1,m2;            /* mouse event rectangles */
  155. static WORD m1flag,m2flag;        /* flags for mouse events 1,2 */
  156.  
  157. static WORD keyqueue = 0;        /* last typed character */
  158. static WORD keyqstat = 0;        /* it's shift status */
  159. static WORD fastpoll = 50;        /* fast poll interval */
  160.  
  161. WORD work_in[] = {1,1,1,1,1,1,1,1,1,1,2};/* Input to GSX parameter array */
  162. WORD work_out[57];            /* Output from GSX parameter array */
  163.  
  164. WORD contrl[12];            /* storage wasted for bindings */
  165. WORD intin[128];
  166. WORD ptsin[128];
  167. WORD intout[128];
  168. WORD ptsout[128];
  169.  
  170. /* the resource file symbols */
  171.  
  172. #ifdef GEMPRG
  173. # include "atari_rs.h"
  174. extern OBJECT *rs_trindex[];
  175. #endif
  176.  
  177. /* forward declarations (when necessary) */
  178.  
  179. void pop_up();
  180. void wi_getwork();
  181. void wi_close();
  182. void sl_update();
  183. void rq_redraw();
  184. WORD do_form();
  185. WORD *rc2pts();
  186. int  wputc();
  187.  
  188. #else                    /* not GEM */
  189.  
  190. # define CONTERM *((char *) 0x484L)    /* system's conterm byte */
  191. char    sconterm;            /* saved conterm byte */
  192.  
  193. char *logbase;                /* logical screen base */
  194.  
  195. int    cursor = 1;            /* cursor currently visible? */
  196. # ifdef MWC
  197. extern    int _fputt();            /* standard output putc routine */
  198. # endif
  199. #endif
  200.  
  201. #ifndef GEMACC
  202. # ifdef MWC
  203. long *_stksize = (long *) 4096;        /* stack size in bytes, becomes ptr */
  204. #  define STACK _stksize
  205. # endif
  206. # ifdef __TURBOC__
  207. extern long *_StkLim;            /* initialized to stack limit */
  208. #  define STACK _StkLim
  209. # endif
  210.  
  211. # define STKMAGIC 0x31415927L        /* magic to check overflow */
  212. #endif
  213.  
  214. void eihalt();
  215.  
  216. #ifndef GEMACC
  217. #ifdef __TURBOC__
  218. static void watchtick(void,...);    /* function called at timer tick */
  219. static void (*orgtick)(void,...);    /* original timertick handler */
  220. #else
  221. static void watchtick();        /* function called at timer tick */
  222. static void (*orgtick)();        /* original timertick handler */
  223. #endif
  224. static long watchcnt;            /* actual watchdog counter */
  225. static long watchnet;            /* watchdog while in NET */
  226. static long watchsh;            /* watchdog while in SHELL */
  227. static unsigned watchhw;        /* watchdog hardware reset */
  228. #endif
  229.  
  230. static void lat_start(),lat_stop(),lat_raw(),lat_status();
  231.  
  232.  
  233. /* Called at startup time to set up console I/O, memory heap */
  234. /* also sets and saves lots of other things on the Atari.... */
  235.  
  236. ioinit()
  237. {
  238. #ifdef GEM
  239.     WORD d;
  240. # ifdef GEMACC
  241.     char net[30];
  242. # endif
  243. #else
  244.     long sav_ssp;            /* saved stackpointer for Super() */
  245. #endif
  246.  
  247. #if (defined(MWC) && (MWC < 300))    /* pre-3.0 MW C? */
  248.     /* set the handler for trap #5. this will be called using the */
  249.     /* micro_rtx() function, and will disable/enable interrupts */
  250.     trap_x_save = (void (*)()) Setexc(0x25,trap_x);
  251. #else
  252.     /* set the handler for trap #7. this will be called using the */
  253.     /* _VtrapB_() function, and will disable/enable interrupts */
  254.     trap_x_save = (void (*)()) Setexc(0x27,trap_x);
  255. #endif
  256.  
  257. #ifndef GEMACC
  258.     STACK[0] = STACK[16] =        /* mark stack for overflow check */
  259.     STACK[32] = STKMAGIC;
  260.  
  261.     orgtick = (void (*)()) Setexc(0x100,watchtick); /* install watchdog ticker */
  262. #endif
  263.  
  264. #if (OUTBUF && !GEM)
  265.     ttbuf = malloc(BUFSIZ);
  266.     setbuf(stdout,ttbuf);
  267. #endif
  268.  
  269. #ifdef GEM
  270.     /* re-route output from "stdout" to window handler */
  271.  
  272.     stdout->_pt = wputc;        /* character output handler */
  273.     stdout->_ff |= _FERR;